package com.industrial.premu.controller;

import cn.hutool.core.util.ArrayUtil;
import com.industrial.common.core.utils.StringUtils;
import com.industrial.common.core.utils.poi.ExcelUtil;
import com.industrial.common.core.web.controller.BaseController;
import com.industrial.common.core.web.domain.AjaxResult;
import com.industrial.common.core.web.page.TableDataInfo;
import com.industrial.common.security.utils.SecurityUtils;
import com.industrial.premu.domain.PreMuAnalysisPolicyImple;
import com.industrial.premu.domain.PremuPioneerCounty;
import com.industrial.premu.service.IPreMuAnalysisPolicyImpleService;
import com.industrial.system.api.domain.SysUser;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.List;
import java.util.Set;

/**
 * 差别化政策执行分析Controller
 *
 * @author ruoyi
 * @date 2024-03-30
 */
@RestController
@RequestMapping("/policyimple/imple")
public class PreMuAnalysisPolicyImpleController extends BaseController
{
    @Autowired
    private IPreMuAnalysisPolicyImpleService preMuAnalysisPolicyImpleService;

    /**
     * 查询差别化政策执行分析列表
     *
     *     public static final String PROVINCE = "p_01_011";
     *     public static final String CITY = "s_01_011";
     *     public static final String COUNTY = "x_01_011";
     */
    @GetMapping("/list")
    public TableDataInfo list(PreMuAnalysisPolicyImple preMuAnalysisPolicyImple)
    {
        Set<String> roles = SecurityUtils.getLoginUser().getRoles();
        SysUser sysUser = SecurityUtils.getLoginUser().getSysUser();
        if(ArrayUtil.contains(roles.toArray(),"p_01_011")){
            if(StringUtils.isBlank(preMuAnalysisPolicyImple.getProvince())){
                preMuAnalysisPolicyImple.setProvince(sysUser.getProvince());
            }
        }else if(ArrayUtil.contains(roles.toArray(),"s_01_011")){
            if(StringUtils.isBlank(preMuAnalysisPolicyImple.getCity())){
                preMuAnalysisPolicyImple.setCity(sysUser.getCity());
            }
        }else if(ArrayUtil.contains(roles.toArray(),"x_01_011")){
            if(StringUtils.isBlank(preMuAnalysisPolicyImple.getCounty())){
                preMuAnalysisPolicyImple.setCounty(sysUser.getDistrict());
            }
        }
        startPage();
        List<PreMuAnalysisPolicyImple> list = preMuAnalysisPolicyImpleService.selectPreMuAnalysisPolicyImpleList(preMuAnalysisPolicyImple);
        return getDataTable(list);
    }

    /**
     * 导出差别化政策执行分析列表
     */

    @PostMapping("/export")
    public void export(HttpServletResponse response, PreMuAnalysisPolicyImple preMuAnalysisPolicyImple)
    {
        List<PreMuAnalysisPolicyImple> list = preMuAnalysisPolicyImpleService.selectPreMuAnalysisPolicyImpleList(preMuAnalysisPolicyImple);
        ExcelUtil<PreMuAnalysisPolicyImple> util = new ExcelUtil<PreMuAnalysisPolicyImple>(PreMuAnalysisPolicyImple.class);
        util.exportExcel(response, list, "差别化政策执行分析数据");
    }

    /**
     * 获取差别化政策执行分析详细信息
     */

    @GetMapping(value = "/{baseId}")
    public AjaxResult getInfo(@PathVariable("baseId") String baseId)
    {
        return success(preMuAnalysisPolicyImpleService.selectPreMuAnalysisPolicyImpleByBaseId(baseId));
    }

    /**
     * 新增差别化政策执行分析
     */

    @PostMapping
    public AjaxResult add(@RequestBody PreMuAnalysisPolicyImple preMuAnalysisPolicyImple)
    {
        return toAjax(preMuAnalysisPolicyImpleService.insertPreMuAnalysisPolicyImple(preMuAnalysisPolicyImple));
    }

    /**
     * 修改差别化政策执行分析
     */

    @PutMapping
    public AjaxResult edit(@RequestBody PreMuAnalysisPolicyImple preMuAnalysisPolicyImple)
    {
        return toAjax(preMuAnalysisPolicyImpleService.updatePreMuAnalysisPolicyImple(preMuAnalysisPolicyImple));
    }

    /**
     * 删除差别化政策执行分析
     */

    @DeleteMapping("/{baseIds}")
    public AjaxResult remove(@PathVariable String[] baseIds)
    {
        return toAjax(preMuAnalysisPolicyImpleService.deletePreMuAnalysisPolicyImpleByBaseIds(baseIds));
    }

    /**
     * 导出模版
     * @param response
     * @throws IOException
     */
    @GetMapping("/importTemplate/policy_ans")
    public void importTemplate(HttpServletResponse response) throws IOException
    {
        ExcelUtil<PreMuAnalysisPolicyImple> util = new ExcelUtil<PreMuAnalysisPolicyImple>(PreMuAnalysisPolicyImple.class);
        util.importTemplateExcel(response, "差别化政策执行分析","差别化政策执行分析");
    }

    /**
     * 导入模版数据
     * @param file
     * @return
     */
    @PostMapping("/importTemplateData")
    public AjaxResult importTemplateData(@RequestPart("file")MultipartFile file){
        return preMuAnalysisPolicyImpleService.importTemplateData(file);
    }


    /**
     * 查询报告
     * @param params
     * @return
     */
    @GetMapping("/queryBgDetailCount")
    public AjaxResult queryBgDetailCount(PreMuAnalysisPolicyImple params){
        return preMuAnalysisPolicyImpleService.queryBgDetailCount(params);
    }


    /**
     * 查谒正向反向激励的占比
     * @return
     */
    @GetMapping("/queryZfjl")
    public AjaxResult queryZfjl(PreMuAnalysisPolicyImple params){
        return preMuAnalysisPolicyImpleService.queryZfjl(params);
    }

    /**
     * 查谒差别化政策柱状图
     * @return
     */
    @GetMapping("/queryCbhzcZzt")
    public AjaxResult queryCbhzcZzt(PreMuAnalysisPolicyImple params){
        return preMuAnalysisPolicyImpleService.queryCbhzcZzt(params);
    }

    /**
     * 查谒差别化政策发布部门
     * @return
     */
    @GetMapping("/queryReleaseDept")
    public AjaxResult queryReleaseDept(PreMuAnalysisPolicyImple params){
        return preMuAnalysisPolicyImpleService.queryReleaseDept(params);
    }

    @GetMapping("/queryCountyPolicyDetailInfo")
    public AjaxResult queryCountyPolicyDetailInfo(PreMuAnalysisPolicyImple params){
        return preMuAnalysisPolicyImpleService.queryCountyPolicyDetailInfo(params);
    }

    @GetMapping("/selectYdWz")
    public  AjaxResult selectYdWz(PreMuAnalysisPolicyImple params){
        return preMuAnalysisPolicyImpleService.selectYdWz(params);
    }
}